package com.dimples.dd.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dimples.dd.common.pojo.PageResult;
import com.dimples.dd.security.core.util.SecurityUtils;
import com.dimples.dd.system.enums.notice.NoticeReadStatusEnum;
import com.dimples.dd.system.mapper.SystemUserNoticeMapper;
import com.dimples.dd.system.model.entity.SystemUserNoticeDO;
import com.dimples.dd.system.model.query.NoticePageQuery;
import com.dimples.dd.system.model.vo.UserNoticePageVO;
import com.dimples.dd.system.service.SystemUserNoticeService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class SystemUserNoticeServiceImpl extends ServiceImpl<SystemUserNoticeMapper, SystemUserNoticeDO> implements SystemUserNoticeService {

    @Override
    public boolean readAll() {
        Long userId = SecurityUtils.getUserId();
        return this.update(new LambdaUpdateWrapper<SystemUserNoticeDO>()
                .eq(SystemUserNoticeDO::getUserId, userId)
                .eq(SystemUserNoticeDO::getIsRead, NoticeReadStatusEnum.UN_READ)
                .set(SystemUserNoticeDO::getIsRead, NoticeReadStatusEnum.IS_READ)
        );
    }

    @Override
    public PageResult<UserNoticePageVO> selectMyNoticePage(NoticePageQuery pageQuery) {
        return this.getBaseMapper().selectMyNoticePage(pageQuery);
    }
}
